//
//  HelpImageView.m
//  Mooker
//
//  Created by Jikui Peng on 12-9-3.
//  Copyright (c) 2012年 banma. All rights reserved.
//

#import "HelpImageView.h"

@interface HelpImageView ()<UIGestureRecognizerDelegate>

- (void)handleGesture:(UIGestureRecognizer *)recognizer;
@end

@implementation HelpImageView

@synthesize delegate = _delegate;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        self.userInteractionEnabled = YES;
        self.backgroundColor = [UIColor clearColor];
        
        UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleGesture:)];
        recognizer.delegate = self;
        [self addGestureRecognizer:recognizer];
        
        UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleGesture:)];
        swipeGesture.direction = UISwipeGestureRecognizerDirectionDown;
        [self addGestureRecognizer:swipeGesture];
        
        swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleGesture:)];
        swipeGesture.direction = UISwipeGestureRecognizerDirectionUp;
        [self addGestureRecognizer:swipeGesture];
        
        swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleGesture:)];
        swipeGesture.direction = UISwipeGestureRecognizerDirectionLeft;
        [self addGestureRecognizer:swipeGesture];
        
        swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleGesture:)];
        swipeGesture.direction = UISwipeGestureRecognizerDirectionRight;
        [self addGestureRecognizer:swipeGesture];
    }
    return self;
}

- (void)handleGesture:(UIGestureRecognizer *)recognizer;
{
    if (recognizer.state == UIGestureRecognizerStateRecognized) {
        [UIView animateWithDuration:.5
                              delay:0.0 options:UIViewAnimationCurveEaseInOut
                         animations:^{
                             self.alpha = 0.0;
                         }
                         completion:^(BOOL finished) {
                             //退出
                             [self removeFromSuperview];
                             if (_delegate && [_delegate respondsToSelector:@selector(helpImageViewDidClosed)])
                             {
                                 [_delegate helpImageViewDidClosed];
                             }
                         }];
    }

}

@end
